package com.ym.medical.service.impl;

import com.ym.core.utils.tkmybatis.BaseSVImpl;
import com.ym.medical.dao.OrderFlowRecordDao;
import com.ym.medical.domain.entity.OrderFlowRecordEntity;
import com.ym.medical.domain.param.OrderFlowRecordParam;
import com.ym.medical.service.IOrderFlowRecordSV;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 订单流转记录Service业务层处理
 *
 * @author ym
 * @date 2020-08-24
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OrderFlowRecordSVImpl extends BaseSVImpl<OrderFlowRecordEntity, OrderFlowRecordDao> implements IOrderFlowRecordSV {
	@Override
	public long save(OrderFlowRecordEntity orderFlowRecord) {
		this.insert(orderFlowRecord);
		return orderFlowRecord.getId();
	}

	@Override
	public int updateById(OrderFlowRecordEntity orderFlowRecord) {
		return this.updateById(orderFlowRecord);
	}

	@Override
	public OrderFlowRecordEntity findById(long orderFlowRecordId) {
		return selectById(orderFlowRecordId);
	}

	@Override
	public OrderFlowRecordEntity findByModel(OrderFlowRecordParam orderFlowRecordModel) {
		List<OrderFlowRecordEntity> orderFlowRecords = list(orderFlowRecordModel);
		return orderFlowRecords.isEmpty() ? null : orderFlowRecords.get(0);
	}

	@Override
	public List<OrderFlowRecordEntity> list(OrderFlowRecordParam orderFlowRecordModel) {
		return this.selectList(orderFlowRecordModel.covert());
	}


	@Override
	public OrderFlowRecordEntity findNewByOrderId(Long orderId) {
		return mapper.findNewByOrderId(orderId);
	}

	@Override
	public void updateNewByOrderId(OrderFlowRecordEntity orderFlowRecord) {
		mapper.updateNewByOrderId(orderFlowRecord);
	}
}
